package ciyuan.Entity.MagicTexture;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.IPacket;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class MagicTextureEntity extends MobEntity {

    public MagicTextureEntity(EntityType<MagicTextureEntity> entityEntityType, World world) {
        super(entityEntityType,world);
    }

    private long time=System.currentTimeMillis();

    @Override
    public void tick() {
        super.tick();
        BlockPos blockPos = this.blockPosition();
        for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, new AxisAlignedBB(
                blockPos.getX()+8,blockPos.getY()+5,blockPos.getZ()+8,blockPos.getX()-8,blockPos.getY()-2,blockPos.getZ()-8
        ))) {
            if ( blockPos.distSqr(livingentity.getX(),livingentity.getY(),livingentity.getZ(),false) < 64.0D && livingentity instanceof PlayerEntity) {
                livingentity.setHealth(livingentity.getHealth()+0.1F);
            }
        }
        if(System.currentTimeMillis()-time>8000) {
            this.remove();
        }
    }

    @Override
    public boolean isPickable() {
        return false;
    }

    @Override
    public IPacket<?> getAddEntityPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    public static AttributeModifierMap.MutableAttribute createAttributes() {
        return MonsterEntity.createMonsterAttributes().add(Attributes.MAX_HEALTH,10).add(Attributes.MOVEMENT_SPEED, (double)0.0F);
    }

    @Override
    public boolean hurt(DamageSource p_70097_1_, float p_70097_2_) {
        return false;
    }

}
